<?php 
echo "datetime	freememory(k)	usedcpu\n";
while (1){
  $output = array();
	$command = "vmstat | tail -1";
	exec($command, $output);
	$arr = preg_split('/\s+/', trim($output[0]));
	
	$mem_free = (int)$arr[3];//空闲的内存，如果知道总内存则可以做减法
	$cpu_used = (int)$arr[12] + (int)$arr[13];
	
	echo time()."	{$mem_free}	{$cpu_used}\n";
	usleep(100000);//0.1s
}

?>
